package com.easyadmin.modules.stock.controller;


import com.easyadmin.common.aop.annotation.Repeat;
import com.easyadmin.common.web.base.BaseController;
import com.easyadmin.common.web.domain.request.PageDomain;
import com.easyadmin.common.web.domain.response.Result;
import com.easyadmin.common.web.domain.response.module.ResultTable;
import com.easyadmin.modules.stock.domain.SysEtfEntity;
import com.easyadmin.modules.stock.domain.SysFuturesEntity;
import com.easyadmin.modules.stock.service.SysEtfServer;
import com.easyadmin.modules.stock.service.SysFuturesService;
import com.github.pagehelper.PageInfo;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;
import org.springframework.web.servlet.ModelAndView;

@RestController
@RequestMapping("/stock/etf")
public class SysEtfController extends BaseController {

    /**
     * Describe: 基础路径
     */
    private static String MODULE_PATH = "stock/etf/";

    /**
     * Describe: 获取角色列表视图
     * Param ModelAndView
     * Return 用户列表视图
     */
    @GetMapping("main")
    @ApiOperation(value = "获取品种列表视图")
    @PreAuthorize("hasPermission('/stock/etf/main','stock:etf:main')")
    public ModelAndView main() {
        return jumpPage(MODULE_PATH + "main");
    }

    /**
     * Describe: 获取角色新增视图
     * Param ModelAndView
     * Return 角色新增视图
     */
    @GetMapping("add")
    @ApiOperation(value = "获取期货品种新增视图")
    @PreAuthorize("hasPermission('/stock/futures/add','stock:futures:add')")
    public ModelAndView add() {
        return jumpPage(MODULE_PATH + "add");
    }


    @Autowired
    private SysEtfServer sysEtfServer;

    /**
     * 分页查询
     */
    @ResponseBody
    @GetMapping("/list")
    @PreAuthorize("hasPermission('/stock/etf/list','stock:etf:list')")
    public ResultTable list(@ModelAttribute SysEtfEntity sysFuturesEntity, PageDomain pageDomain) {
        PageInfo<SysEtfEntity> pageInfo = sysEtfServer.queryPage(sysFuturesEntity, pageDomain);
        return pageTable(pageInfo.getList(), pageInfo.getTotal());
    }



    /**
     * Describe: 保存期货信息
     * Param SysRole
     * Return 执行结果
     */
    @Repeat
    @PostMapping("/save")
    @ApiOperation(value = "保存期货品种数据")
    @PreAuthorize("hasPermission('/stock/etf/add','stock:etf:add')")
    public Result save(@RequestBody SysEtfEntity sysFuturesEntity) {
        return decide(sysEtfServer.save(sysFuturesEntity));
    }



    /**
     * Describe: 删除某条数据
     * Param: id
     * Return: Result
     */
    @DeleteMapping("/remove/{id}")
    @ApiOperation(value = "删除某条数据")
    @PreAuthorize("hasPermission('/stock/etf/remove','stock:etf:remove')")
    public Result remove(@PathVariable String id) {
        return decide(sysEtfServer.remove(id));
    }


    /**
     * Describe: 获取修改视图
     * Param ModelAndView
     * Return 修改视图
     */
    @GetMapping("edit")
    @ApiOperation(value = "获取修改视图")
    @PreAuthorize("hasPermission('/stock/etf/edit','stock:etf:edit')")
    public ModelAndView edit(ModelAndView modelAndView, String id) {
        modelAndView.addObject("stockFutures", sysEtfServer.getById(id));
        modelAndView.setViewName(MODULE_PATH + "edit");
        return modelAndView;
    }


    /**
     * Describe: 修改角色信息
     * Param SysRole
     * Return 执行结果
     */
    @PutMapping("update")
    @ApiOperation(value = "修改数据")
    @PreAuthorize("hasPermission('/stock/futures/edit','stock:futures:edit')")
    public Result update(@RequestBody SysEtfEntity sysFuturesEntity) {
        return decide(sysEtfServer.update(sysFuturesEntity));
    }


    /**
     * Describe: 批量删除接口
     * Param: ids
     * Return: Result
     */
    @DeleteMapping("batchRemove/{ids}")
    @ApiOperation(value = "批量删除数据")
    @PreAuthorize("hasPermission('/stock/etf/remove','stock:etf:remove')")
    public Result batchRemove(@PathVariable String ids) {
        return decide(sysEtfServer.batchRemove(ids.split(",")));
    }
}
